/*
 * To change this license header, choose License Headers in Project Properties.
 * To change this template file, choose Tools | Templates
 * and open the template in the editor.
 */

package br.ufpr.tads.Rent.view;

import br.ufpr.tads.Rent.model.ClienteDTO;
import br.ufpr.tads.Rent.model.LocacaoDAO;
import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.util.ArrayList;
import java.util.Calendar;
import java.util.Date;
import java.util.List;
import javax.swing.table.AbstractTableModel;

/**
 *
 * @author NI LINDA
 */

public class ModeloTabelaCliente extends AbstractTableModel{
    private String[] colunas=new String[]{"id","Nome","Sobrenome", "Endereço","CPF","RG"};

    private List<ClienteDTO> lista=new ArrayList();
    
    @Override
    public int getRowCount() {
        return this.lista.size();
    }

    @Override
    public int getColumnCount() {
        return this.colunas.length;
    }

    @Override
    public String getColumnName(int index) {
        return this.colunas[index];
    }

    @Override
    public boolean isCellEditable(int row, int column) {
        return false;
        //if(column==0)
            //return false;
        //return true;
    }

    
    public void ModeloTabelaCliente(List<ClienteDTO> lista){
        this.lista=lista;
    }

    @Override
    public Object getValueAt(int rowIndex, int columnIndex) {
        ClienteDTO cli = lista.get(rowIndex);
        switch (columnIndex) {
            case 0: return cli.getIdCliente();
            case 1: return cli.getNome();
            case 2: return cli.getSobrenome();
            case 3: return cli.getEndereco();
            case 4: return cli.getCpf();
            case 5: return cli.getRg();
            default : return null;
        }
    }
    


    public void setListaClientes(List<ClienteDTO> lista) {
        this.lista=lista;
        this.fireTableDataChanged();
    }

    public void limpaTabela() {
        int indice = lista.size()-1;
        if(indice<0)
            indice=0;
        this.lista = new ArrayList();
        this.fireTableRowsDeleted(0,indice);//update JTable
    }

    public ClienteDTO getCliente(int linha){
        return lista.get(linha);
    }
    
}
